package com.editso.haier.result;

import com.editso.haier.entity.Assets;
import com.editso.haier.entity.Commodity;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
public class DetailsAssets {
    private String assetsId;
    private String content;
    private String contentType;
    private Integer other;

    public static DetailsAssets from(Assets assets){
        return new DetailsAssets(
                assets.getId(),
                assets.getContent(),
                assets.getType(),
                assets.getOther()
        );
    }

    public static Map<Integer, List<DetailsAssets>> mergeAssets(Commodity commodity){
        HashMap<Integer, List<DetailsAssets>> map = new HashMap<>();
        for (Assets asset : commodity.getAssets()) {
            if(!map.containsKey(asset.getOther())){
                map.put(asset.getOther(), new ArrayList<>());
            }
            map.get(asset.getOther()).add(from(asset));
        }
        return map;
    }
}
